﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace UberChess
{
    //Objects copied with the Copier must be tagged with the [Serializable] tag.
    public static class Copier
    {
        public static object Copy(object source)
        {
            if (source == null)
                return null;

            else
            {
                IFormatter formatter = new BinaryFormatter();
                Stream stream = new MemoryStream();

                using (stream)
                {
                    formatter.Serialize(stream, source);
                    stream.Seek(0, SeekOrigin.Begin);

                    return formatter.Deserialize(stream);
                }
            }

        }
    }
}
